//
//  ExpertDetailsArticle.m
//
//  Created by 啊  on 16/5/10
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ExpertDetailsArticle.h"


NSString *const kExpertDetailsArticleATags = @"aTags";
NSString *const kExpertDetailsArticleATitle = @"aTitle";
NSString *const kExpertDetailsArticleAAbstract = @"aAbstract";
NSString *const kExpertDetailsArticleACode = @"aCode";
NSString *const kExpertDetailsArticleAArticleUrl = @"aArticleUrl";
NSString *const kExpertDetailsArticleAViewNum = @"aViewNum";


@interface ExpertDetailsArticle ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ExpertDetailsArticle

@synthesize aTags = _aTags;
@synthesize aTitle = _aTitle;
@synthesize aAbstract = _aAbstract;
@synthesize aCode = _aCode;
@synthesize aArticleUrl = _aArticleUrl;
@synthesize aViewNum = _aViewNum;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.aTags = [self objectOrNilForKey:kExpertDetailsArticleATags fromDictionary:dict];
            self.aTitle = [self objectOrNilForKey:kExpertDetailsArticleATitle fromDictionary:dict];
            self.aAbstract = [self objectOrNilForKey:kExpertDetailsArticleAAbstract fromDictionary:dict];
            self.aCode = [self objectOrNilForKey:kExpertDetailsArticleACode fromDictionary:dict];
            self.aArticleUrl = [self objectOrNilForKey:kExpertDetailsArticleAArticleUrl fromDictionary:dict];
            self.aViewNum = [[self objectOrNilForKey:kExpertDetailsArticleAViewNum fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.aTags forKey:kExpertDetailsArticleATags];
    [mutableDict setValue:self.aTitle forKey:kExpertDetailsArticleATitle];
    [mutableDict setValue:self.aAbstract forKey:kExpertDetailsArticleAAbstract];
    [mutableDict setValue:self.aCode forKey:kExpertDetailsArticleACode];
    [mutableDict setValue:self.aArticleUrl forKey:kExpertDetailsArticleAArticleUrl];
    [mutableDict setValue:[NSNumber numberWithDouble:self.aViewNum] forKey:kExpertDetailsArticleAViewNum];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.aTags = [aDecoder decodeObjectForKey:kExpertDetailsArticleATags];
    self.aTitle = [aDecoder decodeObjectForKey:kExpertDetailsArticleATitle];
    self.aAbstract = [aDecoder decodeObjectForKey:kExpertDetailsArticleAAbstract];
    self.aCode = [aDecoder decodeObjectForKey:kExpertDetailsArticleACode];
    self.aArticleUrl = [aDecoder decodeObjectForKey:kExpertDetailsArticleAArticleUrl];
    self.aViewNum = [aDecoder decodeDoubleForKey:kExpertDetailsArticleAViewNum];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_aTags forKey:kExpertDetailsArticleATags];
    [aCoder encodeObject:_aTitle forKey:kExpertDetailsArticleATitle];
    [aCoder encodeObject:_aAbstract forKey:kExpertDetailsArticleAAbstract];
    [aCoder encodeObject:_aCode forKey:kExpertDetailsArticleACode];
    [aCoder encodeObject:_aArticleUrl forKey:kExpertDetailsArticleAArticleUrl];
    [aCoder encodeDouble:_aViewNum forKey:kExpertDetailsArticleAViewNum];
}

- (id)copyWithZone:(NSZone *)zone
{
    ExpertDetailsArticle *copy = [[ExpertDetailsArticle alloc] init];
    
    if (copy) {

        copy.aTags = [self.aTags copyWithZone:zone];
        copy.aTitle = [self.aTitle copyWithZone:zone];
        copy.aAbstract = [self.aAbstract copyWithZone:zone];
        copy.aCode = [self.aCode copyWithZone:zone];
        copy.aArticleUrl = [self.aArticleUrl copyWithZone:zone];
        copy.aViewNum = self.aViewNum;
    }
    
    return copy;
}


@end
